const { default: store } = require("../../utils/store")
const { handleUrlParams, controlShowPage } = require("../../utils/utils")

const pageOptions = {
	// 页面数据
	data: {
		sfz_front: "", // 人像面base64
		sfz_back: "", // 国徽面base64
		showPage: false, // 是否显示页面，用于微信审核
	},
	// 页面载入时
	onLoad(e) {
		this.init(e)
	},
	// 页面初始化
	init(e) {},
	// 页面准备好时
	onReady() {},
	// 页面显示时
	async onShow() {
		const sfz_front = store.sfz_front.get()
		const sfz_back = store.sfz_back.get()
		this.setData({
			sfz_front: sfz_front ? "data:image/jpeg;base64," + sfz_front : "",
			sfz_back: sfz_back ? "data:image/jpeg;base64," + sfz_back : "",
			showPage: await controlShowPage(),
		})
	},
	// 页面隐藏时
	onHide() {},
	// 页面卸载时
	onUnload() {},
	// 下拉页面时
	onPullDownRefresh() {},
	// 到达页面底部时
	onReachBottom() {},
	// 页面滚动时
	onPageScroll() {},
	// 分享时，注：onShareAppMessage不能为async异步函数，会导致不能及时取得返回值，使得分享设置无效
	onShareAppMessage() {
		/* const title = ''
    const path = ''
    const imageUrl = ``

    return {
      title,
      path,
      imageUrl,
    } */
	},
	//跳转到身份证照片上传页面
	handleIdCardUpload(e) {
		console.log(e, "e")
		const fullUrl = handleUrlParams(
			"/informationVerification/pages/shootIdCard/index",
			{
				pageType: e.currentTarget.dataset.pagetype,
			},
		)
		wx.navigateTo({
			url: fullUrl,
		})
	},
	// 下一步
	nextStep() {
		//检查用户是否有上传身份证照片
		if (!this.data.sfz_front || !this.data.sfz_back) {
			wx.showToast({
				title: "请先上传身份证照片",
				icon: "none",
				duration: 2000,
			})
			return
		}
		wx.redirectTo({
			url: "/informationVerification/pages/photoInstructions/index",
		})
	},
}

Page(pageOptions)
